//
//  AKeyApplyVC.m
//  KamunAcademy
//
//  Created by Michael Li on 2018/4/27.
//  Copyright © 2018年 Michael Li. All rights reserved.
//

#import "AKeyApplyVC.h"
#import "NJKWebViewProgressView.h"
#import "NJKWebViewProgress.h"
@interface AKeyApplyVC ()<UIWebViewDelegate, NJKWebViewProgressDelegate>
@property(nonatomic,strong) UIWebView *webView;
@property(nonatomic,strong) AFHTTPSessionManager *manager;
@property(nonatomic,strong) NJKWebViewProgressView *progressView;
@property(nonatomic,strong) NJKWebViewProgress *progressProxy;
@property(nonatomic,strong) NSDictionary *dict;
@property(nonatomic,strong) NSString *link;
@end

@implementation AKeyApplyVC


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar addSubview:_progressView];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [_progressView removeFromSuperview];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"用户协议";
    self.edgesForExtendedLayout = UIRectEdgeAll;
    self.view.backgroundColor = [UIColor whiteColor];
    _webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, kUIScreen.size.width, kUIScreen.size.height)];
    [self.view addSubview:_webView];
     _webView.opaque = NO;
    _webView.backgroundColor = [UIColor whiteColor];
    _progressProxy = [[NJKWebViewProgress alloc] init];
    _webView.delegate = _progressProxy;
    _webView.backgroundColor = kBg;
    _webView.scrollView.showsHorizontalScrollIndicator = NO;
    _progressProxy.webViewProxyDelegate = self;
    _progressProxy.progressDelegate = self;
    CGFloat progressBarHeight = 2.f;
    CGRect navigationBarBounds = self.navigationController.navigationBar.bounds;
    CGRect barFrame = CGRectMake(0, navigationBarBounds.size.height - progressBarHeight, navigationBarBounds.size.width, progressBarHeight);
    _progressView = [[NJKWebViewProgressView alloc] initWithFrame:barFrame];
    [_progressView setProgress:0 animated:YES];
    _progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
    [self loadLink];

}

//
//-(void)popself
//{
//    if (self.webView.canGoBack==YES) {
//        [self.webView goBack];
//    }else{
//        [self.navigationController popViewControllerAnimated:YES];
//    }
//}

-(void)loadLink
{
    
    self.manager = [ AFHTTPSessionManager manager];

            //http://www.qichangkeji.club/gongzhonghaoWeb/page/cardPaper.html
            self.link = @"http://www.qichangkeji.club/gongzhonghaoWeb/page/sjPage.html";

    NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:self.link]];
    [_webView loadRequest:req];
}
#pragma mark - NJKWebViewProgressDelegate
-(void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
{
    [_progressView setProgress:progress animated:YES];
}
@end
